package com.exam.api.modules.exampaper.controller.manager;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.exampaper.domain.TblExamPaper;
import com.exam.api.modules.exampaper.dto.ExamPaperPageDto;
import com.exam.api.modules.exampaper.dto.ExamPaperSaveDto;
import com.exam.api.modules.exampaper.service.TblExamPaperService;
import com.exam.api.modules.exampaper.vo.ExamPaperVO;
import com.exam.api.modules.exampaper.vo.PageExamPaperVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * (管理端) 试卷主表相关接口
 */
@Tag(name = "(管理端) 试卷主表相关接口", description = "(管理端) 试卷主表相关接口")
@RestController
@RequestMapping("/manager/exam-paper")
@TinyResponse
public class TblExamPaperManagerController {

    @Resource
    private TblExamPaperService tblExamPaperService;

    @Operation(summary = "创建试卷", description = "创建试卷")
    @PostMapping("/save")
    public Long saveExamPaper(@RequestBody ExamPaperSaveDto dto) {
        return tblExamPaperService.saveExamPaper(dto);
    }

    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public IPage<PageExamPaperVO> page(@RequestBody ExamPaperPageDto examPaperPageDto) {
        return tblExamPaperService.pageExamPaper(examPaperPageDto);
    }

    @Operation(summary = "修改试卷", description = "修改试卷")
    @PostMapping("/update")
    public void updateTblExamPaper(@RequestBody TblExamPaper tblExamPaper) {
        tblExamPaperService.updateById(tblExamPaper);
    }

    @Operation(summary = "发布", description = "发布")
    @PostMapping("/publish/{id}")
    public void publishSeatLayout(@PathVariable("id") Long id) {
        TblExamPaper tblExamPaper = new TblExamPaper();
        tblExamPaper.setStatus(1);
        tblExamPaper.setId(id);
        tblExamPaper.setPublishTime(LocalDateTime.now());
        tblExamPaperService.updateById(tblExamPaper);
    }

    @Operation(summary = "删除试卷", description = "删除试卷")
    @PostMapping("/delete/{id}")
    public void deleteTblExamPaper(@PathVariable("id") Long id) {
        tblExamPaperService.removeById(id);
    }

    @Operation(summary = "根据ID获取试卷", description = "根据ID获取试卷")
    @PostMapping("/full/{id}")
    public ExamPaperVO getTblExamPaperVO(@PathVariable("id") Long id) {
        return tblExamPaperService.getExamPaperVO(id);
    }

    @Operation(summary = "根据ID获取试卷题目", description = "根据ID获取试卷题目")
    @PostMapping("/{id}")
    public TblExamPaper getTblExamPaper(@PathVariable("id") Long id) {
        return tblExamPaperService.getById(id);
    }
}